﻿using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CrystalQuartz.Demo.Jobs
{
    [DisallowConcurrentExecution]
    public class PrintMessageJob : AbstractQuartzJob
    {
        private static readonly Random Random = new Random();

        protected async override Task Execute(IJobExecutionContext context)
        {
            var color = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("Greetings from HelloJob!");
            Console.ForegroundColor = color;

            var delaySeconds = TimeSpan.FromSeconds(Random.Next(1, 20));

            await Task.Delay(delaySeconds);
        }
    }
}
